package com.blkj.iam.system.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blkj.iam.common.annotation.DataPermission;
import com.blkj.iam.system.model.bo.UserBO;
import com.blkj.iam.system.model.entity.Dept;
import com.blkj.iam.system.model.query.DeptPageQuery;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


@Mapper
public interface DeptMapper extends BaseMapper<Dept> {

    @DataPermission(deptIdColumnName = "id")
    @Override
    List<Dept> selectList(@Param(Constants.WRAPPER) Wrapper<Dept> queryWrapper);

    @Select("SELECT CODE FROM sys_dept WHERE parent_id IS NULL OR parent_id = 0 ORDER BY CODE DESC;")
    List<String> getMaxRootDeptCode();

    @Select("SELECT CODE FROM sys_dept WHERE parent_id = #{parentId} ORDER BY CODE DESC;")
    List<String> getMaxChildDeptCode(Long parentId);

    @Select("SELECT CODE FROM sys_dept WHERE id = #{id};")
    String getDeptCodeById(Long parentId);

    @DataPermission(deptAlias = "u", userAlias = "u")
    Page<Dept> getStationDeptPage(Page<UserBO> page, DeptPageQuery queryParams);
}
